package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.GraftinglabelReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.BladeReturn;
import com.ruoyi.production.service.IBladeReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 刀片退回Controller
 *
 * @author ruoyi
 * @date 2021-07-21
 */
@Api("刀片退回")
@RestController
@RequestMapping("/production/bladere")
public class BladeReturnController extends BaseController
{
    @Autowired
    private IBladeReturnService bladeReturnService;

    /**
     * 查询刀片退回列表
     */
    @ApiOperation("查询刀片退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:list')")
    @GetMapping("/list")
    public TableDataInfo list(BladeReturn bladeReturn)
    {
        startPage();
        List<BladeReturn> list = bladeReturnService.selectBladeReturnList(bladeReturn);
        return getDataTable(list);
    }

    /**
     * 导出刀片退回列表
     */
    @ApiOperation("导出刀片退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:export')")
    @Log(title = "刀片退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BladeReturn bladeReturn)
    {

        List<BladeReturn> list=new ArrayList();
        //通过id来取
        Long a[]=bladeReturn.getBladeReturnIds();
        for(int i=0;i<a.length;i++) {
            BladeReturn list1 = bladeReturnService.selectBladeReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<BladeReturn> util = new ExcelUtil<BladeReturn>(BladeReturn.class);
        return util.exportExcel(list, "刀片退回数据");
    }

    /**
     * 获取刀片退回详细信息
     */
    @ApiOperation("获取刀片退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:query')")
    @GetMapping(value = "/{bladeReturnId}")
    public AjaxResult getInfo(@PathVariable("bladeReturnId") Long bladeReturnId)
    {
        return AjaxResult.success(bladeReturnService.selectBladeReturnById(bladeReturnId));
    }

    /**
     * 新增刀片退回
     */
    @ApiOperation("新增刀片退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:add')")
    @Log(title = "刀片退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BladeReturn bladeReturn)
    {
        return toAjax(bladeReturnService.insertBladeReturn(bladeReturn));
    }

    /**
     * 修改刀片退回
     */
    @ApiOperation("修改刀片退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:bladere:edit,production:bladere:permit')")
    @Log(title = "刀片退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BladeReturn bladeReturn)
    {
        return toAjax(bladeReturnService.updateBladeReturn(bladeReturn));
    }

    /**
     * 删除刀片退回
     */
    @ApiOperation("删除刀片退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:remove')")
    @Log(title = "刀片退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bladeReturnIds}")
    public AjaxResult remove(@PathVariable Long[] bladeReturnIds)
    {
        return toAjax(bladeReturnService.deleteBladeReturnByIds(bladeReturnIds));
    }

    /**
     * 获取刀片类型下拉框
     */
    @ApiOperation("获取刀片类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:type')")
    @GetMapping("/type")
    public TableDataInfo getType(){

        List<BladeReturn> list = bladeReturnService.getBladeType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (BladeReturn bladeReturn:list) {
            Long id = bladeReturn.getBladeTypeId();
            String name = bladeReturn.getBladeType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<BladeReturn> list = bladeReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (BladeReturn bladeReturn:list) {
            Long id = bladeReturn.getUserId();
            String name = bladeReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取品牌下拉框
     */
    @ApiOperation("获取品牌下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:brand')")
    @GetMapping("/brand/{bladeTypeId}")
    public TableDataInfo getBrand(@PathVariable("bladeTypeId") Long bladeTypeId){

        List<String> list = bladeReturnService.getBrand(bladeTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:bladere:origincompany')")
    @GetMapping("/origincompany/{bladeTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("bladeTypeId") Long bladeTypeId){

        List<String> list = bladeReturnService.getOriginCompany(bladeTypeId);
        return getDataTable(list);
    }
}
